<?php
namespace app\common\libs\helper;


/**
 * SQL助手类
 *
 * @Author tanruizheng
 * @DateTime 2021-07-30
 */
class SqlHelper
{
    
    /**
     * 处理sql语句
     *
     * @Author tanruizheng
     * @DateTime 2021-07-30
     * @param [type] $sql
     * @return void
     */
    public function splitSQL($sql){
        //多行聚合成一行
        $sql = str_replace("\r", "\n", $sql);
        $queryArray = explode(";\n",trim($sql));
        $res = [];
        $num = 0;
        foreach ($queryArray as $query) {
            $res[$num] = '';
            $querys = explode("\n",trim($query));
            foreach ($querys as $item) {
                $str = substr($item, 0 ,1);
                if($str != '#' && $str != '-'){
                    $res[$num] .= $item;
                }
            }
            $num++;
        }
        return $res;
    }
}